home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / tvdmx.exe / FILESHOP.PAS < prev    next >
Pascal/Delphi Source File  |  1992-07-16  |  6KB  |  231 lines

  1.  
  2. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  3. {                            }
  4. {    FILESHOP  --Buffered Stream Editing Demo    }
  5. {    tvDMX     --data editing project        }
  6. {                            }
  7. {    Copyright (c) 1992  Randolph Beck        }
  8. {                P.O. Box  56-0487        }
  9. {                Orlando, FL 32856        }
  10. {                CIS:  72361,753        }
  11. {                            }
  12. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  13.  
  14. Program FILESHOP;
  15.  
  16. { This program works like WORKSHOP.PAS, except that it uses data from a
  17.   STREAM instead of in memory.  The object's provisions for error-checking
  18.   are not used but can be expanded by overriding TDmxExpBuf.ErrorFunc().
  19.  
  20.   Modify the strings xInfo and xLabel to change the record structure.  Then
  21.   delete FILESHOP.DAT (if it exists).
  22.  
  23.   See unit file TVDMXBUF.PAS for more information on the TDmxExpBuf object.
  24.  }
  25.  
  26. {$M 16384,8192,655360 }
  27. {$B-,R-,X+,V- }
  28.  
  29. uses  Objects, Drivers, Views, Menus, App, MsgBox,
  30.       RSet, DmxGizma, tvDMXBUF, tvGizma, tvDMXREP;
  31.  
  32. const
  33.     fldNDATE     =  { dBASE-formatted date field }
  34.             ' NN-'^Z^F^V'0' + ^P+char(4) +
  35.            #0'ZN-'^Z^V'0' +
  36.            #0'ZZZN '^Z^F^V'0' + ^P+char(-8) +
  37.            #0^P + char (4);
  38.  
  39.     xLabel =  ' Character Field        +Number       Number     mm-dd-yyyy ';
  40.  
  41.     xInfo  =  ' cccccccccccccccccccc║NNNNNNN.NNN | $nn,nnn.nn |' + fldNDATE;
  42.  
  43.  
  44.     Prefix =  'FILESHOP.DAT --from a tvDMX program by R. Beck'#13#10#26;
  45.         { this string is used as a demo file header }
  46.  
  47.  
  48.     InteriorInfo      :  string [length (xInfo)]  =  xInfo;
  49.     InteriorHeader    :  string [length (xLabel)] =  xLabel;
  50.  
  51.     PrefixInfo        :  string [length (Prefix)] =  Prefix;
  52.  
  53.     cmOpenWin         =  101;
  54.     cmReport          =  102;
  55.  
  56.  
  57. type
  58.     TMyApp     =  OBJECT (TAppA)
  59.     WorkFile   :  TDosStream;  { could be any TStream derivative }
  60.       constructor Init;
  61.       destructor  Done;  VIRTUAL;
  62.       procedure HandleEvent (var Event: TEvent);  VIRTUAL;
  63.       procedure Idle;  VIRTUAL;
  64.       procedure InitMenuBar;  VIRTUAL;
  65.       procedure OpenWindow;
  66.       function  OpenFile (var F : TDosStream;  FName : string)  : boolean;
  67.       procedure CloseFile (var F : TDosStream);
  68.     end;
  69.  
  70.  
  71.  
  72.   { ══ TMyApp ════════════════════════════════════════════════════════════ }
  73.  
  74.  
  75. constructor TMyApp.Init;
  76. begin
  77.   TAppA.Init;
  78.  
  79.   If OpenFile (WorkFile, 'FILESHOP.DAT') then
  80.     begin
  81.     OpenWindow;  { open the data window }
  82.     MessageBox (^C'tvDMX Fileshop'^M^M^C'(c) 1992  Randolph Beck',
  83.                 nil, mfInformation + mfOKButton);
  84.     end
  85.    else
  86.     begin
  87.     DisableCommands ([cmOpenWin]);
  88.     MessageBox ('Error initializing file.', nil, mfError + mfOKButton);
  89.     end;
  90.  
  91. end;
  92.  
  93.  
  94. destructor TMyApp.Done;
  95. begin
  96.   CloseFile (WorkFile);
  97.   TAppA.Done;
  98. end;
  99.  
  100.  
  101. procedure TMyApp.HandleEvent (var Event: TEvent);
  102.  
  103.     procedure DoReport;
  104.     begin
  105.       DmxReportBox ('Working', 'Processing report...'^M^M^C'FILESHOP.OUT',
  106.     New (PDmxReportFile, Init (Message (DeskTop, evCommand, cmDMX_RollCall, @Self),
  107.          '|', TRUE, 50,78, 'FILESHOP.OUT')));
  108.     end;
  109.  
  110. begin
  111.   TAppA.HandleEvent (Event);
  112.   If Event.What = evCommand then
  113.     begin
  114.     Case Event.Command of
  115.       cmOpenWin:    OpenWindow;
  116.       cmReport:        DoReport;
  117.      else
  118.       Exit;
  119.       end;
  120.     ClearEvent (Event);
  121.     end;
  122. end;
  123.  
  124.  
  125. procedure TMyApp.Idle;
  126. begin
  127.   TAppA.Idle;
  128.   If (Message (DeskTop, evCommand, cmDMX_RollCall, @Self) <> nil) then
  129.     EnableCommands ([cmReport])
  130.    else
  131.     DisableCommands ([cmReport]);
  132. end;
  133.  
  134.  
  135. procedure TMyApp.InitMenuBar;
  136. var  R: TRect;
  137. begin
  138.   GetExtent (R);
  139.   R.B.Y := R.A.Y + 1;
  140.   MenuBar := New (PMenuBar, Init (R, NewMenu (
  141.     NewSubMenu ('~F~ileshop', hcNoContext, NewMenu (
  142.       NewItem ('~O~pen',    'F4',   kbF4,   cmOpenWin, hcNoContext,
  143.       NewItem ('~R~eport',  'F9',   kbF9,   cmReport,  hcNoContext,
  144.       NewLine (
  145.       NewSoundItem (hcNoContext,
  146.       NewVideoItem (hcNoContext,
  147.       NewLine (
  148.       NewItem ('e~X~it',  'Alt-X',  kbAltX, cmQuit,    hcNoContext,
  149.       nil)))))))),
  150.     NewSubMenu ('~W~indow', hcNoContext, NewMenu (
  151.       NewItem ('~S~ize/Move', 'Ctrl-F5', kbCtrlF5, cmResize, hcNoContext,
  152.       NewItem ('~Z~oom',      'F5',  kbF5,    cmZoom,    hcNoContext,
  153.       NewItem ('~T~ile',      '',    kbNoKey, cmTile,    hcNoContext,
  154.       NewItem ('C~a~scade',   '',    kbNoKey, cmCascade, hcNoContext,
  155.       NewItem ('~N~ext',      'F6',  kbF6,    cmNext,    hcNoContext,
  156.       NewItem ('~P~revious', 'Shift-F6', kbShiftF6, cmPrev, hcNoContext,
  157.       NewItem ('~C~lose', 'Alt-F3',  kbAltF3, cmClose,   hcNoContext,
  158.       NewLine (
  159.       NewItem ('~U~ser screen', 'Alt-F5',  kbAltF5, cmUserScreen, hcNoContext,
  160.       nil)))))))))),
  161.     nil)))
  162.   ));
  163. end;
  164.  
  165.  
  166. procedure TMyApp.OpenWindow;
  167. var  R  : TRect;
  168. begin
  169.   AssignWinRect (R, length (xLabel) + 2, 0);
  170.  
  171.   { Reminder:  The stream used for WorkFile must already be initialized,
  172.                and be able to read and write data to and from the stream. }
  173.  
  174.   DeskTop^.Insert (ValidView (
  175.                    New (PDmxExpBufWin, Init (R,
  176.                                        'Fileshop',
  177.                                        NextWindowNumber,
  178.                                        InteriorInfo,
  179.                                        WorkFile,      { TStream-derivative }
  180.                                        length (PrefixInfo),  { prefix size }
  181.                                        InteriorHeader,
  182.                                        10))
  183.                     ));
  184. end;
  185.  
  186.  
  187. function  TMyApp.OpenFile (var F : TDosStream;  FName : string)  : boolean;
  188. var  Len : longint;
  189. begin
  190.   With F do
  191.     begin
  192.     Init (FName, stOpen);
  193.     If Status <> stOk then
  194.       begin
  195.       Done;
  196.       Init (FName, stCreate);
  197.       Done;
  198.       Init (FName, stOpen);
  199.       end;
  200.     If Status = stOk then
  201.       begin
  202.       Len := GetSize;
  203.       If Len < length (PrefixInfo) then
  204.         begin
  205.         Seek (0);
  206.         Reset;
  207.         Write (PrefixInfo [1], length (PrefixInfo));
  208.         end;
  209.       end;
  210.     OpenFile := (Status = stOk);
  211.     end;
  212. end;
  213.  
  214.  
  215. procedure TMyApp.CloseFile (var F : TDosStream);
  216. begin
  217.   F.Done
  218. end;
  219.  
  220.  
  221.   { ══════════════════════════════════════════════════════════════════════ }
  222.  
  223. var
  224.     MyApp      :  TMyApp;
  225.  
  226. Begin
  227.   MyApp.Init;
  228.   MyApp.Run;
  229.   MyApp.Done;
  230. End.
  231.